﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Collections;
using System.Data;
using CE.Database;

/// <summary>
/// Summary description for CarTurboEngineDB
/// </summary>
/// 
namespace CE.Provider
{
    public class CarTurboEngineDB
    {
        public CarTurboEngineDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        public Int64 Insert(CarTurboEngine carturboengine)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "[sprocProviderCarTurboEngineInsertUpdateSingleItem]";

            SortedList _sPara = new SortedList();
            _sPara.Add("@ProviderCarTurboEngineId", carturboengine.ProviderCarTurboEngineId);
            _sPara.Add("@ProviderCompanyId", carturboengine.ProviderCompanyId);
            _sPara.Add("@IsTurbo", carturboengine.IsTurbo == true ? 1 : 0);
            _sPara.Add("@TurboEngineRate", carturboengine.TurboEngineRate);
            _sPara.Add("@RefCEUserId", carturboengine.RefCEUserId);
            _sPara.Add("@Status", carturboengine.Status);
            _sPara.Add("@Finfo1", carturboengine.FInfo1);
            _sPara.Add("@Dinfo1", carturboengine.DInfo1);
            #region Parameter
            //_sPara.Add("@Info1", carturboengine.Info1);
            //_sPara.Add("@Info2", carturboengine.Info2);
            //_sPara.Add("@Info3", carturboengine.Info3);
            //_sPara.Add("@Info4", carturboengine.Info4);
            //_sPara.Add("@Info5", carturboengine.Info5);
            //_sPara.Add("@NInfo1", carturboengine.NInfo1);
            //_sPara.Add("@NInfo2", carturboengine.NInfo2);
            //_sPara.Add("@FInfo1", carturboengine.FInfo1);
            //_sPara.Add("@FInfo2", carturboengine.FInfo2);
            //_sPara.Add("@DInfo1", carturboengine.DInfo1);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public CarTurboEngine GetCarTurboEngine(Int64 ProviderCompanyId, bool IsTurbo)
        {
            CarTurboEngine _carturbo = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderCarTurboEngineSelectSingleItem";

            SortedList _spara = new SortedList();
            
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);
            _spara.Add("@IsTurbo", IsTurbo);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _carturbo = new CarTurboEngine();
                    _carturbo = FillDataRecord(_dt, 0);
                }
            }
            return _carturbo;
        }

        private CarTurboEngine FillDataRecord(DataTable myDataTable, int RowId)
        {
            CarTurboEngine myCarTurboEngine = new CarTurboEngine();
            myCarTurboEngine.ProviderCarTurboEngineId = Convert.ToInt64(myDataTable.Rows[RowId]["ProviderCarTurboEngineId"].ToString());
            myCarTurboEngine.ProviderCompanyId = Convert.ToInt64(myDataTable.Rows[RowId]["ProviderCompanyId"].ToString());
            myCarTurboEngine.IsTurbo = Convert.ToBoolean(myDataTable.Rows[RowId]["IsTurbo"].ToString());
            myCarTurboEngine.TurboEngineRate = Convert.ToSingle(myDataTable.Rows[RowId]["TurboEngineRate"].ToString());
            myCarTurboEngine.RefCEUserId = Convert.ToInt64(myDataTable.Rows[RowId]["RefCEUserId"].ToString());
            myCarTurboEngine.Status = Convert.ToBoolean(myDataTable.Rows[RowId]["Status"].ToString());
            myCarTurboEngine.CreatedDate = Convert.ToDateTime(myDataTable.Rows[RowId]["CreatedDate"].ToString());
            myCarTurboEngine.ModifiedDate = Convert.ToDateTime(myDataTable.Rows[RowId]["ModifiedDate"].ToString());

            if (myDataTable.Rows[RowId]["FInfo1"].ToString() != "")
                myCarTurboEngine.FInfo1 = Convert.ToSingle(myDataTable.Rows[RowId]["FInfo1"].ToString());

            if (myDataTable.Rows[RowId]["DInfo1"].ToString() != "")
                myCarTurboEngine.DInfo1 = Convert.ToDateTime(myDataTable.Rows[RowId]["DInfo1"].ToString());
            else
                myCarTurboEngine.DInfo1 = Convert.ToDateTime(myDataTable.Rows[RowId]["ModifiedDate"].ToString());
            return myCarTurboEngine;
        }

    }
}